package models

import (
	"github.com/jinzhu/gorm"
	"kop/modules/chat/entity"
)

func AutoMigrate(dB *gorm.DB) {

	dB.AutoMigrate(new(entity.ServerChat))
	dB.AutoMigrate(new(entity.GuildChat))
}

func GetServerChats(dB *gorm.DB, serverID, page, pageNum int32) ([]entity.ServerChat, error) {

	var chats []entity.ServerChat
	return chats, dB.Where(entity.ServerChat{ServerID: serverID}).Order("id DESC").Limit(pageNum).Offset((page - 1) * pageNum).Find(&chats).Error
}
